home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / gnuemacs_dev1_00.lha / comint.el < prev    next >
Text File  |  1992-12-19  |  63KB  |  1,513 lines

  1. ;;; -*-Emacs-Lisp-*- General command interpreter in a window stuff
  2. ;;; Copyright Olin Shivers (1988).
  3. ;;; Please imagine a long, tedious, legalistic 5-page gnu-style copyright
  4. ;;; notice appearing here to the effect that you may use this code any
  5. ;;; way you like, as long as you don't charge money for it, remove this
  6. ;;; notice, or hold me liable for its results.
  7.  
  8. ;;; The changelog is at the end of this file.
  9.  
  10. ;;; Please send me bug reports, bug fixes, and extensions, so that I can
  11. ;;; merge them into the master source.
  12. ;;;     - Olin Shivers (shivers@cs.cmu.edu)
  13.  
  14. ;;; I hope that this generalizes shell mode, lisp mode, tea mode, soar mode,...
  15. ;;; This file defines a general command-interpreter-in-a-buffer package
  16. ;;; (comint mode). The idea is that you can build specific process-in-a-buffer
  17. ;;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, ....
  18. ;;; This way, all these specific packages share a common base functionality, 
  19. ;;; and a common set of bindings, which makes them easier to use (and
  20. ;;; saves code, implementation time, etc., etc.).
  21.  
  22. ;;; Several packages are already defined using comint mode:
  23. ;;; - cmushell.el defines a shell-in-a-buffer mode.
  24. ;;; - cmulisp.el defines a simple lisp-in-a-buffer mode.
  25. ;;; Cmushell and cmulisp mode are similar to, and intended to replace,
  26. ;;; their counterparts in the standard gnu emacs release (in shell.el). 
  27. ;;; These replacements are more featureful, robust, and uniform than the 
  28. ;;; released versions. The key bindings in lisp mode are also more compatible
  29. ;;; with the bindings of Hemlock and Zwei (the Lisp Machine emacs).
  30. ;;;
  31. ;;; - The file cmuscheme.el defines a scheme-in-a-buffer mode.
  32. ;;; - The file tea.el tunes scheme and inferior-scheme modes for T.
  33. ;;; - The file soar.el tunes lisp and inferior-lisp modes for Soar.
  34. ;;; - cmutex.el defines tex and latex modes that invoke tex, latex, bibtex,
  35. ;;;   previewers, and printers from within emacs.
  36. ;;; - background.el allows csh-like job control inside emacs.
  37. ;;; It is pretty easy to make new derived modes for other processes.
  38.  
  39. ;;; For documentation on the functionality provided by comint mode, and
  40. ;;; the hooks available for customising it, see the comments below.
  41. ;;; For further information on the standard derived modes (shell, 
  42. ;;; inferior-lisp, inferior-scheme, ...), see the relevant source files.
  43.  
  44. ;;; For hints on converting existing process modes (e.g., tex-mode,
  45. ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
  46. ;;; instead of shell-mode, see the notes at the end of this file.
  47.  
  48. (provide 'comint)
  49. (defconst comint-version "2.02")
  50.  
  51.  
  52. ;;; Brief Command Documentation:
  53. ;;;============================================================================
  54. ;;; Comint Mode Commands: (common to all derived modes, like cmushell & cmulisp
  55. ;;; mode)
  56. ;;;
  57. ;;; m-p        comint-previous-similar-input   Cycle backward in input history
  58. ;;; m-n        comint-next-similar-input       Cycle forward
  59. ;;; c-c r   comint-previous-input-matching  Search backward in input history
  60. ;;; return  comint-send-input
  61. ;;; c-a     comint-bol                      Beginning of line; skip prompt.
  62. ;;; c-d        comint-delchar-or-maybe-eof     Delete char unless at end of buff.
  63. ;;; c-c c-u comint-kill-input                ^u
  64. ;;; c-c c-w backward-kill-word            ^w
  65. ;;; c-c c-c comint-interrupt-subjob         ^c
  66. ;;; c-c c-z comint-stop-subjob                ^z
  67. ;;; c-c c-\ comint-quit-subjob                ^\
  68. ;;; c-c c-d comint-send-eof                ^d
  69. ;;; c-c c-o comint-kill-output            Delete last batch of process output
  70. ;;; c-c c-r comint-show-output            Show last batch of process output
  71. ;;;
  72. ;;; Not bound by default in comint-mode
  73. ;;; send-invisible            Read a line w/o echo, and send to proc
  74. ;;; (These are bound in shell-mode)
  75. ;;; comint-dynamic-complete        Complete filename at point.
  76. ;;; comint-dynamic-list-completions    List completions in help buffer.
  77. ;;; comint-replace-by-expanded-filename    Expand and complete filename at point;
  78. ;;;                    replace with expanded/completed name.
  79. ;;; comint-kill-subjob            No mercy.
  80. ;;; comint-continue-subjob        Send CONT signal to buffer's process
  81. ;;;                    group. Useful if you accidentally
  82. ;;;                    suspend your process (with C-c C-z).
  83. ;;;
  84. ;;; Bound for RMS -- I prefer the input history stuff, but you might like 'em.
  85. ;;; m-P       comint-msearch-input        Search backwards for prompt
  86. ;;; m-N    comint-psearch-input        Search forwards for prompt
  87. ;;; C-cR   comint-msearch-input-matching Search backwards for prompt & string
  88.  
  89. ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings.
  90. ;;; comint-load-hook is run after loading in this package.
  91.  
  92.  
  93. ;;; Buffer Local Variables:
  94. ;;;============================================================================
  95. ;;; Comint mode buffer local variables:
  96. ;;;     comint-prompt-regexp    - string       comint-bol uses to match prompt.
  97. ;;;     comint-last-input-start - marker           ...
  98. ;;;     comint-last-input-end   - marker       For comint-kill-output command
  99. ;;;     input-ring-size         - integer      For the input history
  100. ;;;     input-ring              - ring             mechanism
  101. ;;;     input-ring-index        - marker           ...
  102. ;;;     comint-last-input-match - string           ...
  103. ;;;     comint-get-old-input    - function     Hooks for specific 
  104. ;;;     comint-input-sentinel   - function         process-in-a-buffer
  105. ;;;     comint-input-filter     - function         modes.
  106. ;;;     comint-input-send    - function
  107. ;;;     comint-eol-on-send    - boolean
  108.  
  109. (defvar comint-prompt-regexp "^"
  110.   "Regexp to recognise prompts in the inferior process.
  111. Defaults to \"^\", the null string at BOL.
  112.  
  113. Good choices:
  114.   Canonical Lisp: \"^[^> ]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
  115.   Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
  116.   franz: \"^\\(->\\|<[0-9]*>:\\) *\"
  117.   kcl: \"^>+ *\"
  118.   shell: \"^[^#$%>]*[#$%>] *\"
  119.   T: \"^>+ *\"
  120.  
  121. This is a good thing to set in mode hooks.")
  122.  
  123. (defvar input-ring-size 30
  124.   "Size of input history ring.")
  125.  
  126. ;;; Here are the per-interpreter hooks.
  127. (defvar comint-get-old-input (function comint-get-old-input-default)
  128.   "Function that submits old text in comint mode.
  129. This function is called when return is typed while the point is in old text.
  130. It returns the text to be submitted as process input.  The default is
  131. comint-get-old-input-default, which grabs the current line, and strips off
  132. leading text matching comint-prompt-regexp")
  133.  
  134. (defvar comint-input-sentinel (function ignore)
  135.   "Called on each input submitted to comint mode process by comint-send-input.
  136. Thus it can, for instance, track cd/pushd/popd commands issued to the csh.")
  137.  
  138. (defvar comint-input-filter
  139.   (function (lambda (str)
  140.     (and (not (string-match "\\`\\s *\\'" str))
  141.      (> (length str) 2))))
  142.   "Predicate for filtering additions to input history.
  143. Only inputs answering true to this function are saved on the input
  144. history list. Default is to save anything longer than two characters
  145. that isn't all whitespace. If an existing item in the history exactly
  146. matches the new input, the existing item is removed and the new input
  147. is added.")
  148.  
  149. (defvar comint-input-sender (function comint-simple-send)
  150.   "Function to actually send to PROCESS the STRING submitted by user.
  151. Usually this is just 'comint-simple-send, but if your mode needs to 
  152. massage the input string, this is your hook. This is called from
  153. the user command comint-send-input. comint-simple-send just sends
  154. the string plus a newline.")
  155.  
  156. (defvar comint-eol-on-send 'T
  157.   "If non-nil, then jump to the end of the line before sending input to process.
  158. See COMINT-SEND-INPUT")
  159.  
  160. (defvar comint-mode-hook '()
  161.   "Called upon entry into comint-mode
  162. This is run before the process is cranked up.")
  163.  
  164. (defvar comint-exec-hook '()
  165.   "Called each time a process is exec'd by comint-exec.
  166. This is called after the process is cranked up.  It is useful for things that
  167. must be done each time a process is executed in a comint-mode buffer (e.g.,
  168. (process-kill-without-query)). In contrast, the comint-mode-hook is only
  169. executed once when the buffer is created.")
  170.  
  171. (defvar comint-mode-map nil)
  172.  
  173. (defun comint-mode ()
  174.   "Major mode for interacting with an inferior interpreter.
  175. Interpreter name is same as buffer name, sans the asterisks.
  176. Return at end of buffer sends line as input.
  177. Return not at end copies rest of line to end and sends it.
  178. Setting mode variable comint-eol-on-send means jump to the end of the line
  179. before submitting new input.
  180.  
  181. This mode is typically customised to create inferior-lisp-mode,
  182. shell-mode, etc.. This can be done by setting the hooks
  183. comint-input-sentinel, comint-input-filter, comint-input-sender and
  184. comint-get-old-input to appropriate functions, and the variable
  185. comint-prompt-regexp to the appropriate regular expression.
  186.  
  187. An input history is maintained of size input-ring-size, and
  188. can be accessed with the commands comint-next-input [\\[comint-next-input]] and 
  189. comint-previous-input [\\[comint-previous-input]]. Commands not keybound by
  190. default are send-invisible, comint-dynamic-complete, and 
  191. comint-list-dynamic-completions.
  192.  
  193. If you accidentally suspend your process, use \\[comint-continue-subjob]
  194. to continue it.
  195.  
  196. \\{comint-mode-map}
  197.  
  198. Entry to this mode runs the hooks on comint-mode-hook"
  199.   (interactive)
  200.   (let ((old-ring (get-input-ring))
  201.     (old-ptyp comint-ptyp)) ; preserve across local var kill. gross.
  202. ;   (kill-all-local-variables) ; Removed 1/15/90 Olin
  203.     (setq major-mode 'comint-mode)
  204.     (setq mode-name "Comint")
  205.     (setq mode-line-process '(": %s"))
  206.     (use-local-map comint-mode-map)
  207.     (make-local-variable 'comint-last-input-start)
  208.     (setq comint-last-input-start (make-marker))
  209.     (make-local-variable 'comint-last-input-end)
  210.     (setq comint-last-input-end (make-marker))
  211.     (make-local-variable 'comint-last-input-match)
  212.     (setq comint-last-input-match "")
  213.     (make-local-variable 'comint-prompt-regexp) ; Don't set; default
  214.     (make-local-variable 'input-ring-size)      ; ...to global val.
  215.     (make-local-variable 'input-ring)
  216.     (setq input-ring nil) ; make sure it has a value here
  217.     (make-local-variable 'input-ring-index)
  218.     (setq input-ring-index 0)
  219.     (make-local-variable 'comint-get-old-input)
  220.     (make-local-variable 'comint-input-sentinel)
  221.     (make-local-variable 'comint-input-filter)  
  222.     (make-local-variable 'comint-input-sender)
  223.     (make-local-variable 'comint-eol-on-send)
  224.     (make-local-variable 'comint-ptyp)
  225.     (setq comint-ptyp old-ptyp)
  226.     (run-hooks 'comint-mode-hook)
  227.     ;Do this after the hook so the user can mung INPUT-RING-SIZE w/his hook.
  228.     ;The test is so we don't lose history if we run comint-mode twice in
  229.     ;a buffer.
  230.     (set-input-ring (if (ring-p old-ring)
  231.                          old-ring
  232.              (make-ring input-ring-size)))))
  233.  
  234. ;;; The old-ptyp stuff above is because we have to preserve the value of
  235. ;;; comint-ptyp across calls to comint-mode, in spite of the
  236. ;;; kill-all-local-variables that it does. Blech. Hopefully, this will all
  237. ;;; go away when a later release fixes the signalling bug.
  238. ;;; (Later: I removed the kill-all-local-variables, but have left this
  239. ;;; other code in place just in case I reverse myself.)
  240.  
  241. (if comint-mode-map
  242.     nil
  243.   (setq comint-mode-map (make-sparse-keymap))
  244.   ;;(define-key comint-mode-map "\ep" 'comint-previous-input)
  245.   ;;(define-key comint-mode-map "\en" 'comint-next-input)
  246.   (define-key comint-mode-map "\ep" 'comint-previous-similar-input)
  247.   (define-key comint-mode-map "\en" 'comint-next-similar-input)
  248.   (define-key comint-mode-map "\es" 'comint-previous-similar-input)
  249.   (define-key comint-mode-map "\C-m" 'comint-send-input)
  250.   (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
  251.   (define-key comint-mode-map "\C-a" 'comint-bol)
  252.   (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
  253.   (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
  254.   (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
  255.   (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
  256.   (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
  257.   ;; Retained for compatibility with older shell mode, even though
  258.   ;; ^D at end of buffer does the same thing.
  259.   (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
  260.   (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
  261.   (define-key comint-mode-map "\C-cr"    'comint-previous-input-matching)
  262.   (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
  263.   ;;; Here's the prompt-search stuff I installed for RMS to try...
  264.   (define-key comint-mode-map "\eP" 'comint-msearch-input)
  265.   (define-key comint-mode-map "\eN" 'comint-psearch-input)
  266.   (define-key comint-mode-map "\C-cR" 'comint-msearch-input-matching))
  267.  
  268.  
  269. ;;; This function is used to make a full copy of the comint mode map,
  270. ;;; so that client modes won't interfere with each other. This function
  271. ;;; isn't necessary in emacs 18.5x, but we keep it around for 18.4x versions.
  272. (defun full-copy-sparse-keymap (km)
  273.   "Recursively copy the sparse keymap KM"
  274.   (cond ((consp km)
  275.      (cons (full-copy-sparse-keymap (car km))
  276.            (full-copy-sparse-keymap (cdr km))))
  277.     (t (copy-keymap km))))
  278.  
  279. (defun comint-check-proc (buffer-name)
  280.   "True if there is a process associated w/buffer BUFFER-NAME, and
  281. it is alive (status RUN or STOP)."
  282.   (let ((proc (get-buffer-process buffer-name)))
  283.     (and proc (memq (process-status proc) '(run stop)))))
  284.  
  285. (defun comint-mark ()
  286.   "Returns the process-mark of the current buffer."
  287.   (process-mark (get-buffer-process (current-buffer))))
  288.  
  289. ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it ()
  290. ;;; for the second argument (program).
  291. (defun make-comint (name program &optional startfile &rest switches)
  292.   (let* ((buffer
  293.       ;; Don't create the buffer in any other mode, since
  294.       ;; we are going to set it to comint-mode.  This fixes
  295.       ;; problems with default mode being text and text-mode-hook
  296.       ;; turning on auto-fill, thus causing shell buffers to be
  297.       ;; in auto-fill, certainly not what the user intended!
  298.       (let ((default-major-mode 'fundamental-mode))
  299.         (get-buffer-create (concat "*" name "*"))))
  300.      (proc (get-buffer-process buffer)))
  301.     ;; If no process, or nuked process, crank up a new one and put buffer in
  302.     ;; comint mode. Otherwise, leave buffer and existing process alone.
  303.     (cond ((or (not proc) (not (memq (process-status proc) '(run stop))))
  304.        (save-excursion
  305.          (set-buffer buffer)
  306.          (comint-mode)) ; Install local vars, mode, keymap, ...
  307.        (comint-exec buffer name program startfile switches)))
  308.     buffer))
  309.  
  310. (fset 'make-shell 'make-comint) ; mostly compatible...
  311.  
  312. (defvar comint-ptyp t
  313.   "True if communications via pty; false if by pipe. Buffer local.
  314. This is to work around a bug in emacs process signalling.")
  315.  
  316. (defun comint-exec (buffer name command startfile switches)
  317.   "Fires up a process in buffer for comint modes.
  318. Blasts any old process running in the buffer. Doesn't set the buffer mode.
  319. You can use this to cheaply run a series of processes in the same comint
  320. buffer. The hook comint-exec-hook is run after each exec."
  321.   (save-excursion
  322.     (set-buffer buffer)
  323.     (let ((proc (get-buffer-process buffer))) ; Blast any old process.
  324.       (if proc (delete-process proc)))
  325.     ;; Crank up a new process
  326.     (let ((proc (comint-exec-1 name buffer command switches)))
  327.       (make-local-variable 'comint-ptyp)
  328.       (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
  329.       ;; Jump to the end, and set the process mark.
  330.       (goto-char (point-max))
  331.       (set-marker (process-mark proc) (point))
  332.       ;; Feed it the startfile.
  333.       (cond (startfile
  334.          ;;This is guaranteed to wait long enough
  335.          ;;but has bad results if the comint does not prompt at all
  336.          ;;         "(while (= size (buffer-size))"
  337.          ;;         "  (sleep-for 1))"
  338.          ;;I hope 1 second is enough!
  339.          (sleep-for 1) 
  340.          (goto-char (point-max)) 
  341.          (insert-file-contents startfile)
  342.          (setq startfile (buffer-substring (point) (point-max)))
  343.          (delete-region (point) (point-max))
  344.          (comint-send-string proc startfile))))
  345.     (run-hooks 'comint-exec-hook)
  346.     buffer))
  347.  
  348. ;;; This auxiliary function cranks up the process for comint-exec in
  349. ;;; the appropriate environment. It is twice as long as it should be
  350. ;;; because emacs has two distinct mechanisms for manipulating the
  351. ;;; process environment, selected at compile time with the
  352. ;;; MAINTAIN-ENVIRONMENT #define. In one case, process-environment
  353. ;;; is bound; in the other it isn't.
  354.  
  355. (defun comint-exec-1 (name buffer command switches)
  356.   (if (boundp 'process-environment) ; Not a completely reliable test.
  357.       (let ((process-environment
  358.          (comint-update-env process-environment
  359.                 (list (format "TERMCAP=emacs:co#%d:tc=unknown"
  360.                           (screen-width))
  361.                       "TERM=emacs"
  362.                       "EMACS=t"))))
  363.     (apply 'start-process name buffer command switches))
  364.  
  365.       (let ((tcapv (getenv "TERMCAP"))
  366.         (termv (getenv "TERM"))
  367.         (emv   (getenv "EMACS")))
  368.     (unwind-protect
  369.          (progn (setenv "TERMCAP" (format "emacs:co#%d:tc=unknown"
  370.                           (screen-width)))
  371.             (setenv "TERM" "emacs")
  372.             (setenv "EMACS" "t")
  373.             (apply 'start-process name buffer command switches))
  374.       (setenv "TERMCAP" tcapv)
  375.       (setenv "TERM"    termv)
  376.       (setenv "EMACS"   emv)))))
  377.          
  378.  
  379.  
  380. ;; This is just (append new old-env) that compresses out shadowed entries.
  381. ;; It's also pretty ugly, mostly due to elisp's horrible iteration structures.
  382. (defun comint-update-env (old-env new)
  383.   (let ((ans (reverse new))
  384.     (vars (mapcar (function (lambda (vv)
  385.             (and (string-match "^[^=]*=" vv)
  386.                  (substring vv 0 (match-end 0)))))
  387.               new)))
  388.     (while old-env
  389.       (let* ((vv (car old-env)) ; vv is var=value
  390.          (var (and (string-match "^[^=]*=" vv)
  391.                (substring vv 0 (match-end 0)))))
  392.     (setq old-env (cdr old-env))
  393.     (cond ((not (and var (comint-mem var vars)))
  394.            (if var (setq var (cons var vars)))
  395.            (setq ans (cons vv ans))))))
  396.     (nreverse ans)))
  397.  
  398. ;;; This should be in emacs, but it isn't.
  399. (defun comint-mem (item list &optional elt=)
  400.   "Test to see if ITEM is equal to an item in LIST.
  401. Option comparison function ELT= defaults to equal."
  402.   (let ((elt= (or elt= (function equal)))
  403.     (done nil))
  404.     (while (and list (not done))
  405.       (if (funcall elt= item (car list))
  406.       (setq done list)
  407.       (setq list (cdr list))))
  408.     done))
  409.  
  410.  
  411. ;;; Ring Code
  412. ;;;============================================================================
  413. ;;; This code defines a ring data structure. A ring is a 
  414. ;;;     (hd-index tl-index . vector) 
  415. ;;; list. You can insert to, remove from, and rotate a ring. When the ring
  416. ;;; fills up, insertions cause the oldest elts to be quietly dropped.
  417. ;;;
  418. ;;; HEAD = index of the newest item on the ring.
  419. ;;; TAIL = index of the oldest item on the ring.
  420. ;;;
  421. ;;; These functions are used by the input history mechanism, but they can
  422. ;;; be used for other purposes as well.
  423.  
  424.  
  425. ;;; These next four forms are to provide a more persistent means of
  426. ;;; keeping the buffer history -- they can be disabled by setting
  427. ;;; use-buffer-local-input-ring to NIL.
  428. (defvar use-buffer-local-input-ring nil)
  429.  
  430. ;;; A list of vectors of the form [<buffer-name> <input-ring>]; these let
  431. ;;; the input history be associated with the name of the buffer, so that it
  432. ;;; persists from one instance of the buffer to another (especially useful
  433. ;;; with gdb buffers), and even one invocation of emacs to another.
  434. (defvar *buffer-histories-list* nil)
  435.  
  436. (defun get-input-ring ()
  437.   (if use-buffer-local-input-ring
  438.       (and (boundp 'input-ring)
  439.            input-ring)
  440.       (let ((list *buffer-histories-list*)
  441.             (buffer (current-buffer))
  442.             (ring nil))
  443.         (while (and list (not ring))
  444.           (cond ((eq buffer (get-buffer (aref (car list) 0)))
  445.                  (aset (car list) 1 buffer)
  446.                  (setq ring (aref (car list) 2)))
  447.                 ((eq buffer (aref (car list) 1))
  448.                  (aset (car list) 0 (buffer-name buffer))
  449.                  (setq ring (aref (car list) 2))))
  450.           (setq list (cdr list)))
  451.         (if (not ring)
  452.             (set-input-ring nil)
  453.             ring))))
  454.  
  455. (defun set-input-ring (ring-to-use)
  456.   (if (not (ring-p ring-to-use))
  457.       (setq ring-to-use (make-ring input-ring-size)))
  458.   (if use-buffer-local-input-ring
  459.       (progn
  460.         (make-local-variable 'input-ring)
  461.         (setq input-ring ring-to-use))
  462.       (progn
  463.         (setq *buffer-histories-list*
  464.               (cons (vector (buffer-name (current-buffer)) (current-buffer) ring-to-use)
  465.                     *buffer-histories-list*))
  466.         ring-to-use)))
  467.  
  468. (defun ring-p (x) 
  469.   "T if X is a ring; NIL otherwise."
  470.   (and (consp x) (integerp (car x))
  471.        (consp (cdr x)) (integerp (car (cdr x)))
  472.        (vectorp (cdr (cdr x)))))
  473.  
  474. (defun ring-head (ring)
  475.   (car ring))
  476. (defun set-ring-head (ring value)
  477.   (let ((len (length (cdr (cdr ring)))))
  478.        (if (or (< value 0)
  479.                (>= value len))
  480.            (error (format "Attempt to make head of ring (size = %d) be %d"
  481.                           len value)))
  482.        (setcar ring value)))
  483.  
  484. (defun ring-tail (ring)
  485.   (car (cdr ring)))
  486. (defun set-ring-tail (ring value)
  487.   (let ((len (length (cdr (cdr ring)))))
  488.        (if (or (< value 0)
  489.                (>= value len))
  490.            (error (format "Attempt to make head of ring (size = %d) be %d"
  491.                           len value)))
  492.        (setcar (cdr ring) value)))
  493.  
  494. (defun ring-vector (ring)
  495.   (cdr (cdr ring)))
  496.  
  497. (defun make-ring (size)
  498.   "Make a ring that can contain SIZE elts"
  499.   (cons 1 (cons 0 (make-vector (+ size 1) nil))))
  500.  
  501. (defun ring-plus1 (index veclen)
  502.   "INDEX+1, with wraparound"
  503.   (let ((new-index (+ index 1)))
  504.     (if (= new-index veclen) 0 new-index)))
  505.  
  506. (defun ring-minus1 (index veclen)
  507.   "INDEX-1, with wraparound"
  508.   (- (if (= 0 index) veclen index) 1))
  509.  
  510. (defun ring-plus (index increment veclen)
  511.   "INDEX+INCREMENT, with wraparound."
  512.   ;; use comint-mod here as we don't have control over increment
  513.   ;; arg since this function is called with user-supplied increment
  514.   (comint-mod (+ index increment) veclen))
  515.  
  516. (defun ring-length (ring)
  517.   "Number of elts in the ring."
  518.   (let ((hd (ring-head ring)) 
  519.         (tl (ring-tail ring)) 
  520.         (siz (length (ring-vector ring))))
  521.     (let ((len (if (<= hd tl) (+ 1 (- tl hd)) (+ 1 tl (- siz hd)))))
  522.       (if (= len siz) 0 len))))
  523.  
  524. (defun ring-empty-p (ring)
  525.   (= 0 (ring-length ring)))
  526.  
  527. (defun ring-insert-new (ring item)
  528.   "Insert a new item onto the ring. If the ring is full, dump the oldest
  529. item to make room."       
  530.   (let* ((vec (ring-vector ring))  
  531.          (len (length vec))
  532.      (new-hd (ring-minus1 (ring-head ring) len)))
  533.     (set-ring-head ring new-hd)
  534.     (aset vec new-hd item)
  535.     (if (ring-empty-p ring)                 ;overflow -- dump one off the tail.
  536.         (set-ring-tail ring (ring-minus1 (ring-tail ring) len)))))
  537.  
  538. (defun ring-remove-oldest (ring)
  539.   "Remove the oldest item retained on the ring."
  540.   (if (ring-empty-p ring) (error "Ring empty")
  541.       (let ((tl (ring-tail ring))  
  542.             (vec (ring-vector ring)))
  543.     (set-ring-tail ring (ring-minus1 tl (length vec)))
  544.     (aref vec tl))))
  545.  
  546. (defun ring-remove-newest (ring)
  547.   "Remove the newest item retained on the ring."
  548.   (if (ring-empty-p ring) (error "Ring empty")
  549.       (let ((hd (ring-head ring))  
  550.             (vec (ring-vector ring)))
  551.     (set-ring-head ring (ring-plus1 hd (length vec)))
  552.     (aref vec hd))))
  553.  
  554. (defun comint-mod (n m)
  555.   "Returns N mod M. M is positive. Answer is guaranteed to be non-negative, 
  556. and less than (the absolute value of) M."
  557.   (if (= m 0) (if (< n 0) (- n) n)
  558.     (let ((n (% n m)))
  559.       (if (>= n 0) n
  560.         (+ n
  561.            (if (>= m 0) m (- m)))))))   ; (abs m)
  562.  
  563. (defun ring-ref (ring index)
  564.   (let ((numelts (ring-length ring)))
  565.     (if (= numelts 0) (error "indexed empty ring")
  566.     (let* ((hd (ring-head ring))
  567.                (tl (ring-tail ring))
  568.                (vec (ring-vector ring))
  569.            (index (comint-mod index numelts))
  570.            (vec-index (comint-mod (+ index hd) 
  571.                       (length vec))))
  572.       (aref vec vec-index)))))
  573.  
  574. (defun ring-search-and-destroy (ring victim predicate)
  575.   "Search for a matching victim in the ring according to predicate
  576. and destructively remove it if found."
  577.   (cond ((not (ring-empty-p ring))
  578.      (let* ((hd (ring-head ring))
  579.         (tl (ring-tail ring))
  580.         (vec (ring-vector ring))
  581.         (len (length vec))
  582.         (top (if (>= tl hd) (+ tl 1) len))
  583.         (i hd)
  584.         (done nil))
  585.        (while (and (not done) (< i top))
  586.          (cond ((funcall predicate victim (aref vec i))
  587.             (while (> i hd)
  588.               (aset vec i (aref vec (- i 1)))
  589.               (setq i (- i 1)))
  590.             (set-ring-head ring (ring-plus1 hd len))
  591.             (setq done t)))
  592.          (setq i (+ i 1)))
  593.        (cond ((and (not done) (< tl hd))
  594.           (setq i 0)
  595.           (while (and (not done) (<= i tl))
  596.             (cond ((funcall predicate victim (aref vec i))
  597.                (while (< i tl)
  598.                  (aset vec i (aref vec (+ i 1)))
  599.                  (setq i (+ i 1)))
  600.                (set-ring-tail ring (ring-minus1 tl len))
  601.                (setq done t)))
  602.             (setq i (+ i 1)))))))))
  603.  
  604.  
  605. ;;; Input history retrieval commands
  606. ;;; M-p -- previous input    M-n -- next input
  607. ;;; C-c r -- previous input matching
  608. ;;; ===========================================================================
  609.  
  610. (defun comint-previous-input (arg)
  611.   "Cycle backwards through input history."
  612.   (interactive "*p")
  613.   (let* ((ring (get-input-ring))
  614.          (len (ring-length ring)))
  615.     (cond ((<= len 0)
  616.        (message "Empty input ring")
  617.        (ding))
  618.       ((not (comint-after-pmark-p))
  619.        (message "Not after process mark")
  620.        (ding))
  621.       (t
  622.        (cond ((eq last-command 'comint-previous-input)
  623.           (delete-region comint-last-input-start (point)))
  624.          ((eq last-command 'comint-previous-similar-input)
  625.           (delete-region 
  626.            (comint-mark)
  627.            (point)))
  628.          (t                          
  629.           (setq input-ring-index
  630.             (if (> arg 0) -1
  631.                 (if (< arg 0) 1 0)))
  632.                   (set-marker comint-last-input-start (point))))
  633.        (setq input-ring-index (comint-mod (+ input-ring-index arg) len))
  634.        (message "%d" (1+ input-ring-index))
  635.        (insert (ring-ref ring input-ring-index))
  636.        (setq this-command 'comint-previous-input)))))
  637.      
  638. (defun comint-next-input (arg)
  639.   "Cycle forwards through input history."
  640.   (interactive "*p")
  641.   (comint-previous-input (- arg)))
  642.  
  643. (defvar comint-last-input-match ""
  644.   "Last string searched for by comint input history search, for defaulting.
  645. Buffer local variable.") 
  646.  
  647. (defun comint-previous-input-matching (str)
  648.   "Searches backwards through input history for substring match."
  649.   (interactive (let* ((last-command last-command) ; preserve around r-f-m
  650.               (s (read-from-minibuffer 
  651.              (format "Command substring (default %s): "
  652.                  comint-last-input-match))))
  653.          (list (if (string= s "") comint-last-input-match s))))
  654. ; (interactive "sCommand substring: ")
  655.   (setq comint-last-input-match str) ; update default
  656.   (if (not (eq last-command 'comint-previous-input))
  657.       (setq input-ring-index -1))
  658.   (let* ((ring (get-input-ring))
  659.          (str (regexp-quote str))
  660.         (len (ring-length ring))
  661.     (n (+ input-ring-index 1)))
  662.     (while (and (< n len) (not (string-match str (ring-ref ring n))))
  663.       (setq n (+ n 1)))
  664.     (cond ((< n len)
  665.        (comint-previous-input (- n input-ring-index)))
  666.       (t (if (eq last-command 'comint-previous-input) 
  667.          (setq this-command 'comint-previous-input))
  668.          (message "Not found.")
  669.          (ding)))))
  670.  
  671.  
  672. ;;; These next three commands are alternatives to the input history commands --
  673. ;;; comint-next-input, comint-previous-input and 
  674. ;;; comint-previous-input-matching. They search through the process buffer
  675. ;;; text looking for occurrences of the prompt. RMS likes them better;
  676. ;;; I don't.
  677.  
  678. ;;; comint-msearch-input-matching prompts for a string, not a regexp.
  679. ;;; This could be considered to be the wrong thing. I decided to keep it
  680. ;;; simple, and not make the user worry about regexps. This, of course,
  681. ;;; limits functionality.
  682.  
  683. (defun comint-psearch-input ()
  684.   "Search forwards for next occurrence of prompt and skip to end of line.
  685. \(prompt is anything matching regexp comint-prompt-regexp)"
  686.   (interactive)
  687.   (if (re-search-forward comint-prompt-regexp (point-max) t)
  688.       (end-of-line)
  689.       (error "No occurrence of prompt found")))
  690.  
  691. (defun comint-msearch-input ()
  692.   "Search backwards for previous occurrence of prompt and skip to end of line.
  693. Search starts from beginning of current line."
  694.   (interactive)
  695.   (let ((p (save-excursion
  696.          (beginning-of-line)
  697.          (cond ((re-search-backward comint-prompt-regexp (point-min) t)
  698.             (end-of-line)
  699.             (point))
  700.            (t nil)))))
  701.     (if p (goto-char p)
  702.     (error "No occurrence of prompt found"))))
  703.  
  704. (defun comint-msearch-input-matching (str)
  705.   "Search backwards for occurrence of prompt followed by STRING.
  706. STRING is prompted for, and is NOT a regular expression."
  707.   (interactive (let ((s (read-from-minibuffer 
  708.              (format "Command (default %s): "
  709.                  comint-last-input-match))))
  710.          (list (if (string= s "") comint-last-input-match s))))
  711. ; (interactive "sCommand: ")
  712.   (setq comint-last-input-match str) ; update default
  713.   (let* ((r (concat comint-prompt-regexp (regexp-quote str)))
  714.      (p (save-excursion
  715.           (beginning-of-line)
  716.           (cond ((re-search-backward r (point-min) t)
  717.              (end-of-line)
  718.              (point))
  719.             (t nil)))))
  720.     (if p (goto-char p)
  721.     (error "No match"))))
  722.  
  723. ;;;
  724. ;;; Similar input -- contributed by ccm and highly winning.
  725. ;;;
  726. ;;; Reenter input, removing back to the last insert point if it exists. 
  727. ;;;
  728. (defvar comint-last-similar-string "" 
  729.   "The string last used in a similar string search.")
  730. (defun comint-previous-similar-input (arg)
  731.   "Reenters the last input that matches the string typed so far.  If repeated 
  732. successively older inputs are reentered.  If arg is 1, it will go back
  733. in the history, if -1 it will go forward."
  734.   (interactive "p")
  735.   (if (not (comint-after-pmark-p))
  736.       (error "Not after process mark"))
  737.   (if (not (eq last-command 'comint-previous-similar-input))
  738.       (setq input-ring-index -1
  739.         comint-last-similar-string 
  740.         (buffer-substring 
  741.               (comint-mark)
  742.               (point))))
  743.   (let* ((size (length comint-last-similar-string))
  744.          (ring (get-input-ring))
  745.      (len (ring-length ring))
  746.      (limit (if (= input-ring-index -1)
  747.             (if (= arg 1)
  748.             0
  749.             (- len 1))
  750.             (ring-plus input-ring-index arg len)))
  751.      (n limit)
  752.      (done nil)
  753.      entry)
  754.     (while (and (not done)
  755.         (or (< (length (setq entry (ring-ref ring n))) size)
  756.             (not (string-equal comint-last-similar-string 
  757.                        (substring entry 0 size)))))
  758.       (setq n (ring-plus n arg len))
  759.       (if (= n limit)
  760.       (setq done t)))
  761.     (cond ((not done)
  762.        (setq input-ring-index n)
  763.        (if (eq last-command 'comint-previous-similar-input)
  764.            (delete-region comint-last-input-start (point)) ; repeat
  765.                (set-marker comint-last-input-start (point))) ; 1st time
  766.        (insert (substring entry size)))
  767.       (t (message "Not found.") (ding) (sit-for 1)))))
  768.  
  769. (defun comint-next-similar-input (arg)
  770.   "Reenters the last input that matches the string typed so far.  If repeated 
  771. successively older inputs are reentered.  If arg is 1, it will go forward
  772. in the history, if -1 it will go back."
  773.   (interactive "p")
  774.   (setq this-command 'comint-previous-similar-input)
  775.   (comint-previous-similar-input (- arg)))
  776.  
  777. (defun comint-send-input () 
  778.   "Send input to process.  After the process output mark, sends all text
  779. from the process mark to point as input to the process.  Before the
  780. process output mark, calls value of variable comint-get-old-input to retrieve
  781. old input, copies it to the end of the buffer, and sends it.  A terminal
  782. newline is also inserted into the buffer and sent to the process.  In either
  783. case, value of variable comint-input-sentinel is called on the input before
  784. sending it.  The input is entered into the input history ring, if value of
  785. variable comint-input-filter returns non-nil when called on the input.
  786.  
  787. If variable comint-eol-on-send is non-nil, then point is moved to the end of
  788. line before sending the input.
  789.  
  790. comint-get-old-input, comint-input-sentinel, and comint-input-filter are chosen
  791. according to the command interpreter running in the buffer. E.g.,
  792. If the interpreter is the csh,
  793.     comint-get-old-input is the default: take the current line, discard any
  794.         initial string matching regexp comint-prompt-regexp.
  795.     comint-input-sentinel monitors input for \"cd\", \"pushd\", and \"popd\" 
  796.         commands. When it sees one, it cd's the buffer.
  797.     comint-input-filter is the default: returns T if the input isn't all white
  798.     space.
  799.  
  800. If the comint is Lucid Common Lisp, 
  801.     comint-get-old-input snarfs the sexp ending at point.
  802.     comint-input-sentinel does nothing.
  803.     comint-input-filter returns NIL if the input matches input-filter-regexp,
  804.         which matches (1) all whitespace (2) :a, :c, etc.
  805.  
  806. Similarly for Soar, Scheme, etc.."
  807.   (interactive)
  808.   ;; Note that the input string does not include its terminal newline.
  809.   (let ((proc (get-buffer-process (current-buffer))))
  810.     (if (not proc) (error "Current buffer has no process")
  811.     (let* ((ring (get-input-ring))
  812.                (pmark (process-mark proc))
  813.            (pmark-val (marker-position pmark))
  814.            (input (if (>= (point) pmark-val)
  815.               (progn (if comint-eol-on-send (end-of-line))
  816.                  (buffer-substring pmark (point)))
  817.               (let ((copy (funcall comint-get-old-input)))
  818.                 (goto-char pmark)
  819.                 (insert copy)
  820.                 copy))))
  821.       (insert ?\n)
  822.       (cond ((funcall comint-input-filter input)
  823.          (ring-search-and-destroy
  824.            ring input (function string-equal))
  825.          (ring-insert-new ring input)))
  826.       (funcall comint-input-sentinel input)
  827.       (funcall comint-input-sender proc input)
  828.       (set-marker (process-mark proc) (point))
  829.       (set-marker comint-last-input-end (point))))))
  830.  
  831. (defun comint-get-old-input-default ()
  832.   "Default for comint-get-old-input: take the current line, and discard
  833. any initial text matching comint-prompt-regexp."
  834.   (save-excursion
  835.     (beginning-of-line)
  836.     (comint-skip-prompt)
  837.     (let ((beg (point)))
  838.       (end-of-line)
  839.       (buffer-substring beg (point)))))
  840.  
  841. (defun comint-skip-prompt ()
  842.   "Skip past the text matching regexp comint-prompt-regexp. 
  843. If this takes us past the end of the current line, don't skip at all."
  844.   (let ((eol (save-excursion (end-of-line) (point))))
  845.     (if (and (looking-at comint-prompt-regexp)
  846.          (<= (match-end 0) eol))
  847.     (goto-char (match-end 0)))))
  848.  
  849.  
  850. (defun comint-after-pmark-p ()
  851.   "Is point after the process output marker?"
  852.   ;; Since output could come into the buffer after we looked at the point
  853.   ;; but before we looked at the process marker's value, we explicitly 
  854.   ;; serialise. This is just because I don't know whether or not emacs
  855.   ;; services input during execution of lisp commands.
  856.   (let ((proc-pos (marker-position
  857.            (comint-mark))))
  858.     (<= proc-pos (point))))
  859.  
  860. (defun comint-simple-send (proc string)
  861.   "Default function for sending to PROC input STRING.
  862. This just sends STRING plus a newline. To override this,
  863. set the hook COMINT-INPUT-SENDER."
  864.   (comint-send-string proc string)
  865.   (comint-send-string proc "\n"))
  866.  
  867. (defun comint-bol (arg)
  868.   "Goes to the beginning of line, then skips past the prompt, if any.
  869. If a prefix argument is given (\\[universal-argument]), then no prompt skip 
  870. -- go straight to column 0.
  871.  
  872. The prompt skip is done by skipping text matching the regular expression
  873. comint-prompt-regexp, a buffer local variable.
  874.  
  875. If you don't like this command, reset c-a to beginning-of-line 
  876. in your hook, comint-mode-hook."
  877.   (interactive "P")
  878.   (beginning-of-line)
  879.   (if (null arg) (comint-skip-prompt)))
  880.  
  881. ;;; These two functions are for entering text you don't want echoed or
  882. ;;; saved -- typically passwords to ftp, telnet, or somesuch.
  883. ;;; Just enter m-x send-invisible and type in your line.
  884.  
  885. (defun comint-read-noecho (prompt)
  886.   "Prompt the user with argument PROMPT. Read a single line of text
  887. without echoing, and return it. Note that the keystrokes comprising
  888. the text can still be recovered (temporarily) with \\[view-lossage]. This
  889. may be a security bug for some applications."
  890.   (let ((echo-keystrokes 0)
  891.     (answ "")
  892.     tem)
  893.     (if (and (stringp prompt) (not (string= (message prompt) "")))
  894.     (message prompt))
  895.     (while (not(or  (= (setq tem (read-char)) ?\^m)
  896.             (= tem ?\n)))
  897.       (setq answ (concat answ (char-to-string tem))))
  898.     (message "")
  899.     answ))
  900.  
  901. (defun send-invisible (str)
  902.   "Read a string without echoing, and send it to the process running
  903. in the current buffer. A new-line is additionally sent. String is not 
  904. saved on comint input history list.
  905. Security bug: your string can still be temporarily recovered with
  906. \\[view-lossage]."
  907. ; (interactive (list (comint-read-noecho "Enter non-echoed text")))
  908.   (interactive "P") ; Defeat snooping via C-x esc
  909.   (let ((proc (get-buffer-process (current-buffer))))
  910.     (if (not proc) (error "Current buffer has no process")
  911.     (comint-send-string proc
  912.                 (if (stringp str) str
  913.                 (comint-read-noecho "Enter non-echoed text")))
  914.     (comint-send-string proc "\n"))))
  915.  
  916.  
  917. ;;; Low-level process communication
  918.  
  919. (defvar comint-input-chunk-size 512
  920.   "*Long inputs send to comint processes are broken up into chunks of this size.
  921. If your process is choking on big inputs, try lowering the value.")
  922.  
  923. (defun comint-send-string (proc str)
  924.   "Send PROCESS the contents of STRING as input.
  925. This is equivalent to process-send-string, except that long input strings
  926. are broken up into chunks of size comint-input-chunk-size. Processes
  927. are given a chance to output between chunks. This can help prevent processes
  928. from hanging when you send them long inputs on some OS's."
  929.   (let* ((len (length str))
  930.      (i (min len comint-input-chunk-size)))
  931.     (process-send-string proc (substring str 0 i))
  932.     (while (< i len)
  933.       (let ((next-i (+ i comint-input-chunk-size)))
  934.     (accept-process-output)
  935.     (process-send-string proc (substring str i (min len next-i)))
  936.     (setq i next-i)))))
  937.  
  938. (defun comint-send-region (proc start end)
  939.   "Sends to PROC the region delimited by START and END.
  940. This is a replacement for process-send-region that tries to keep
  941. your process from hanging on long inputs. See comint-send-string."
  942.   (comint-send-string proc (buffer-substring start end)))
  943.  
  944.  
  945. ;;; Random input hackage
  946.  
  947. (defun comint-kill-output ()
  948.   "Kill all output from interpreter since last input."
  949.   (interactive)
  950.   (let ((pmark (comint-mark)))
  951.     (kill-region comint-last-input-end pmark)
  952.     (goto-char pmark)    
  953.     (insert "*** output flushed ***\n")
  954.     (set-marker pmark (point))))
  955.  
  956. (defun comint-show-output ()
  957.   "Display start of this batch of interpreter output at top of window.
  958. Also put cursor there."
  959.   (interactive)
  960.   (goto-char comint-last-input-end)
  961.   (backward-char)
  962.   (beginning-of-line)
  963.   (set-window-start (selected-window) (point))
  964.   (end-of-line))
  965.  
  966. (defun comint-interrupt-subjob ()
  967.   "Interrupt the current subjob."
  968.   (interactive)
  969.   (interrupt-process nil comint-ptyp))
  970.  
  971. (defun comint-kill-subjob ()
  972.   "Send kill signal to the current subjob."
  973.   (interactive)
  974.   (kill-process nil comint-ptyp))
  975.  
  976. (defun comint-quit-subjob ()
  977.   "Send quit signal to the current subjob."
  978.   (interactive)
  979.   (quit-process nil comint-ptyp))
  980.  
  981. (defun comint-stop-subjob ()
  982.   "Stop the current subjob.
  983. WARNING: if there is no current subjob, you can end up suspending
  984. the top-level process running in the buffer. If you accidentally do
  985. this, use \\[comint-continue-subjob] to resume the process. (This
  986. is not a problem with most shells, since they ignore this signal.)"
  987.   (interactive)
  988.   (stop-process nil comint-ptyp))
  989.  
  990. (defun comint-continue-subjob ()
  991.   "Send CONT signal to process buffer's process group.
  992. Useful if you accidentally suspend the top-level process."
  993.   (interactive)
  994.   (continue-process nil comint-ptyp))
  995.  
  996. (defun comint-kill-input ()
  997.   "Kill all text from last stuff output by interpreter to point."
  998.   (interactive)
  999.   (let* ((pmark (comint-mark))
  1000.      (p-pos (marker-position pmark)))
  1001.     (if (> (point) p-pos)
  1002.     (kill-region pmark (point)))))
  1003.  
  1004. (defun comint-delchar-or-maybe-eof (arg)
  1005.   "Delete ARG characters forward, or send an EOF to process if at end of buffer."
  1006.   (interactive "p")
  1007.   (if (eobp)
  1008.       (process-send-eof)
  1009.       (delete-char arg)))
  1010.  
  1011. (defun comint-send-eof ()
  1012.   "Send an EOF to the process in the current buffer."
  1013.   (interactive)
  1014.   (process-send-eof))
  1015.  
  1016.  
  1017. ;;; Support for source-file processing commands.
  1018. ;;;============================================================================
  1019. ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
  1020. ;;; commands that process files of source text (e.g. loading or compiling
  1021. ;;; files). So the corresponding process-in-a-buffer modes have commands
  1022. ;;; for doing this (e.g., lisp-load-file). The functions below are useful
  1023. ;;; for defining these commands.
  1024. ;;;
  1025. ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
  1026. ;;; and Soar, in that they don't know anything about file extensions.
  1027. ;;; So the compile/load interface gets the wrong default occasionally.
  1028. ;;; The load-file/compile-file default mechanism could be smarter -- it
  1029. ;;; doesn't know about the relationship between filename extensions and
  1030. ;;; whether the file is source or executable. If you compile foo.lisp
  1031. ;;; with compile-file, then the next load-file should use foo.bin for
  1032. ;;; the default, not foo.lisp. This is tricky to do right, particularly
  1033. ;;; because the extension for executable files varies so much (.o, .bin,
  1034. ;;; .lbin, .mo, .vo, .ao, ...).
  1035.  
  1036.  
  1037. ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing
  1038. ;;; commands.
  1039. ;;;
  1040. ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
  1041. ;;; want to save the buffer before issuing any process requests to the command
  1042. ;;; interpreter.
  1043. ;;;
  1044. ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
  1045. ;;; for the file to process.
  1046.  
  1047. ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
  1048. ;;;============================================================================
  1049. ;;; This function computes the defaults for the load-file and compile-file
  1050. ;;; commands for tea, soar, cmulisp, and cmuscheme modes. 
  1051. ;;; 
  1052. ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last 
  1053. ;;; source-file processing command. NIL if there hasn't been one yet.
  1054. ;;; - SOURCE-MODES is a list used to determine what buffers contain source
  1055. ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
  1056. ;;; Typically, (lisp-mode) or (scheme-mode).
  1057. ;;; 
  1058. ;;; If the command is given while the cursor is inside a string, *and*
  1059. ;;; the string is an existing filename, *and* the filename is not a directory,
  1060. ;;; then the string is taken as default. This allows you to just position
  1061. ;;; your cursor over a string that's a filename and have it taken as default.
  1062. ;;;
  1063. ;;; If the command is given in a file buffer whose major mode is in
  1064. ;;; SOURCE-MODES, then the the filename is the default file, and the
  1065. ;;; file's directory is the default directory.
  1066. ;;; 
  1067. ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
  1068. ;;; then the default directory & file are what was used in the last source-file
  1069. ;;; processing command (i.e., PREVIOUS-DIR/FILE).  If this is the first time
  1070. ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
  1071. ;;; is the cwd, with no default file. (\"no default file\" = nil)
  1072. ;;; 
  1073. ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
  1074. ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
  1075. ;;; for Soar programs, etc.
  1076. ;;; 
  1077. ;;; The function returns a pair: (default-directory . default-file).
  1078.  
  1079. (defun comint-source-default (previous-dir/file source-modes)
  1080.   (cond ((and buffer-file-name (memq major-mode source-modes))
  1081.      (cons (file-name-directory    buffer-file-name)
  1082.            (file-name-nondirectory buffer-file-name)))
  1083.     (previous-dir/file)
  1084.     (t
  1085.      (cons default-directory nil))))
  1086.  
  1087.  
  1088. ;;; (COMINT-CHECK-SOURCE fname)
  1089. ;;;============================================================================
  1090. ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
  1091. ;;; process-in-a-buffer modes), this function can be called on the filename.
  1092. ;;; If the file is loaded into a buffer, and the buffer is modified, the user
  1093. ;;; is queried to see if he wants to save the buffer before proceeding with
  1094. ;;; the load or compile.
  1095.  
  1096. (defun comint-check-source (fname)
  1097.   (let ((buff (get-file-buffer fname)))
  1098.     (if (and buff
  1099.          (buffer-modified-p buff)
  1100.          (y-or-n-p (format "Save buffer %s first? "
  1101.                    (buffer-name buff))))
  1102.     ;; save BUFF.
  1103.     (let ((old-buffer (current-buffer)))
  1104.       (set-buffer buff)
  1105.       (save-buffer)
  1106.       (set-buffer old-buffer)))))
  1107.  
  1108.  
  1109. ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
  1110. ;;;============================================================================
  1111. ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
  1112. ;;; commands that process source files (like loading or compiling a file).
  1113. ;;; It prompts for the filename, provides a default, if there is one,
  1114. ;;; and returns the result filename.
  1115. ;;; 
  1116. ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
  1117. ;;; 
  1118. ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
  1119. ;;; from the last source processing command.  SOURCE-MODES is a list of major
  1120. ;;; modes used to determine what file buffers contain source files.  (These
  1121. ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
  1122. ;;; then the filename reader will only accept a file that exists.
  1123. ;;; 
  1124. ;;; A typical use:
  1125. ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
  1126. ;;;                                 '(lisp-mode) t))
  1127.  
  1128. ;;; This is pretty stupid about strings. It decides we're in a string
  1129. ;;; if there's a quote on both sides of point on the current line.
  1130. (defun comint-extract-string ()
  1131.   "Returns string around point that starts the current line or nil." 
  1132.   (save-excursion
  1133.     (let* ((point (point))
  1134.        (bol (progn (beginning-of-line) (point)))
  1135.        (eol (progn (end-of-line) (point)))
  1136.        (start (progn (goto-char point) 
  1137.              (and (search-backward "\"" bol t) 
  1138.                   (1+ (point)))))
  1139.        (end (progn (goto-char point)
  1140.                (and (search-forward "\"" eol t)
  1141.                 (1- (point))))))
  1142.       (and start end
  1143.        (buffer-substring start end)))))
  1144.  
  1145. (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
  1146.   (let* ((def (comint-source-default prev-dir/file source-modes))
  1147.          (stringfile (comint-extract-string))
  1148.      (sfile-p (and stringfile
  1149.                (condition-case ()
  1150.                (file-exists-p stringfile)
  1151.              (error nil))
  1152.                (not (file-directory-p stringfile))))
  1153.      (defdir  (if sfile-p (file-name-directory stringfile)
  1154.                       (car def)))
  1155.      (deffile (if sfile-p (file-name-nondirectory stringfile)
  1156.                       (cdr def)))
  1157.      (ans (read-file-name (if deffile (format "%s(default %s) "
  1158.                           prompt    deffile)
  1159.                   prompt)
  1160.                   defdir
  1161.                   (concat defdir deffile)
  1162.                   mustmatch-p)))
  1163.     (list (expand-file-name (substitute-in-file-name ans)))))
  1164.  
  1165. ;;; I am somewhat divided on this string-default feature. It seems
  1166. ;;; to violate the principle-of-least-astonishment, in that it makes
  1167. ;;; the default harder to predict, so you actually have to look and see
  1168. ;;; what the default really is before choosing it. This can trip you up.
  1169. ;;; On the other hand, it can be useful, I guess. I would appreciate feedback
  1170. ;;; on this.
  1171. ;;;     -Olin
  1172.  
  1173.  
  1174. ;;; Simple process query facility.
  1175. ;;; ===========================================================================
  1176. ;;; This function is for commands that want to send a query to the process
  1177. ;;; and show the response to the user. For example, a command to get the
  1178. ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
  1179. ;;; to an inferior Common Lisp process.
  1180. ;;; 
  1181. ;;; This simple facility just sends strings to the inferior process and pops
  1182. ;;; up a window for the process buffer so you can see what the process
  1183. ;;; responds with.  We don't do anything fancy like try to intercept what the
  1184. ;;; process responds with and put it in a pop-up window or on the message
  1185. ;;; line. We just display the buffer. Low tech. Simple. Works good.
  1186.  
  1187. ;;; Send to the inferior process PROC the string STR. Pop-up but do not select
  1188. ;;; a window for the inferior process so that its response can be seen.
  1189. (defun comint-proc-query (proc str)
  1190.   (let* ((proc-buf (process-buffer proc))
  1191.      (proc-mark (process-mark proc)))
  1192.     (display-buffer proc-buf)
  1193.     (set-buffer proc-buf) ; but it's not the selected *window*
  1194.     (let ((proc-win (get-buffer-window proc-buf))
  1195.       (proc-pt (marker-position proc-mark)))
  1196.       (comint-send-string proc str) ; send the query
  1197.       (accept-process-output proc)  ; wait for some output
  1198.       ;; Try to position the proc window so you can see the answer.
  1199.       ;; This is bogus code. If you delete the (sit-for 0), it breaks.
  1200.       ;; I don't know why. Wizards invited to improve it.
  1201.       (if (not (pos-visible-in-window-p proc-pt proc-win))
  1202.       (let ((opoint (window-point proc-win)))
  1203.         (set-window-point proc-win proc-mark) (sit-for 0)
  1204.         (if (not (pos-visible-in-window-p opoint proc-win))
  1205.         (push-mark opoint)
  1206.         (set-window-point proc-win opoint)))))))
  1207.  
  1208.  
  1209. ;;; Filename completion in a buffer
  1210. ;;; ===========================================================================
  1211. ;;; Useful completion functions, courtesy of the Ergo group.
  1212. ;;; M-<Tab> will complete the filename at the cursor as much as possible
  1213. ;;; M-? will display a list of completions in the help buffer.
  1214.  
  1215. ;;; Three commands:
  1216. ;;; comint-dynamic-complete        Complete filename at point.
  1217. ;;; comint-dynamic-list-completions    List completions in help buffer.
  1218. ;;; comint-replace-by-expanded-filename    Expand and complete filename at point;
  1219. ;;;                    replace with expanded/completed name.
  1220.  
  1221. ;;; These are not installed in the comint-mode keymap. But they are
  1222. ;;; available for people who want them. Shell-mode installs them:
  1223. ;;; (define-key cmushell-mode-map "\M-\t" 'comint-dynamic-complete)
  1224. ;;; (define-key cmushell-mode-map "\M-?"  'comint-dynamic-list-completions)))
  1225. ;;;
  1226. ;;; Commands like this are fine things to put in load hooks if you
  1227. ;;; want them present in specific modes. Example:
  1228. ;;; (setq cmushell-load-hook
  1229. ;;;       '((lambda () (define-key lisp-mode-map "\M-\t"
  1230. ;;;                   'comint-replace-by-expanded-filename))))
  1231. ;;;          
  1232.  
  1233.  
  1234. (defvar comint-match-partial-pathname-chars "^][<>{}()!#$^&*\\|?`'^ \t\n\r\b")
  1235.  
  1236. (defun comint-match-partial-pathname ()
  1237.   "Returns the filename at point or causes an error."
  1238.   (save-excursion
  1239.     (skip-chars-backward " \t\n\r")
  1240.     (let ((p (point))
  1241.       p2)
  1242.       (skip-chars-backward comint-match-partial-pathname-chars)
  1243.       (setq p2 (point))
  1244.       (if (= p p2) (error ""))
  1245.       ;; call this just for the side-effect of setting the match-data.
  1246.       (looking-at (concat "[" comint-match-partial-pathname-chars "]+"))
  1247.       (goto-char p)
  1248.       (substitute-in-file-name (buffer-substring p2 p)))))
  1249.  
  1250.  
  1251. (defun comint-replace-by-expanded-filename ()
  1252. "Replace the filename at point with an expanded, canonicalised, and
  1253. completed replacement.
  1254. \"Expanded\" means environment variables (e.g., $HOME) and ~'s are
  1255. replaced with the corresponding directories.  \"Canonicalised\" means ..
  1256. and \. are removed, and the filename is made absolute instead of relative.
  1257. See functions expand-file-name and substitute-in-file-name. See also
  1258. comint-dynamic-complete."
  1259.   (interactive)
  1260.   (let* ((pathname (comint-match-partial-pathname))
  1261.      (pathdir (file-name-directory pathname))
  1262.      (pathnondir (file-name-nondirectory pathname))
  1263.      (completion (file-name-completion pathnondir
  1264.                        (or pathdir default-directory))))
  1265.     (cond ((null completion)
  1266.        (message "No completions of %s." pathname)
  1267.        (ding))
  1268.       ((eql completion t)
  1269.        (message "Unique completion."))
  1270.       (t                ; this means a string was returned.
  1271.        (delete-region (match-beginning 0) (match-end 0))
  1272.        (insert (expand-file-name (concat pathdir completion)))))))
  1273.  
  1274.  
  1275. (defun comint-dynamic-complete ()
  1276.   "Dynamically complete the filename at point.
  1277. This function is similar to comint-replace-by-expanded-filename, except
  1278. that it won't change parts of the filename already entered in the buffer; 
  1279. it just adds completion characters to the end of the filename."
  1280.   (interactive)
  1281.   (let* ((pathname (comint-match-partial-pathname))
  1282.      (pathdir (file-name-directory pathname))
  1283.      (pathnondir (file-name-nondirectory pathname))
  1284.      (completion (file-name-completion  pathnondir
  1285.                        (or pathdir default-directory))))
  1286.     (cond ((null completion)
  1287.        (message "No completions of %s." pathname)
  1288.        (ding))
  1289.       ((eql completion t)
  1290.        (message "Unique completion."))
  1291.           ((equal pathnondir completion)
  1292.            (comint-dynamic-list-completions t))
  1293.       (t                ; this means a string was returned.
  1294.        (goto-char (match-end 0))
  1295.        (insert (substring completion (length pathnondir)))))))
  1296.  
  1297. (defun comint-dynamic-list-completions (&optional revert-soonest)
  1298.   "List in help buffer all possible completions of the filename at point."
  1299.   (interactive)
  1300.   (let* ((pathname (comint-match-partial-pathname))
  1301.      (pathdir (file-name-directory pathname))
  1302.      (pathnondir (file-name-nondirectory pathname))
  1303.      (completions
  1304.       (file-name-all-completions pathnondir
  1305.                      (or pathdir default-directory))))
  1306.     (cond ((null completions)
  1307.        (message "No completions of %s." pathname)
  1308.        (ding))
  1309.       (t
  1310.        (let ((conf (current-window-configuration)))
  1311.          (with-output-to-temp-buffer "*Help*"
  1312.            (display-completion-list completions))
  1313.          (sit-for 0)
  1314.          (if (not revert-soonest) (message "Hit space to flush."))
  1315.          (let ((ch (next-command-event (allocate-event))))
  1316.            (if revert-soonest 
  1317.                    (progn
  1318.                      (if (key-press-event-p ch)
  1319.                          (set-window-configuration conf)
  1320.                          (setq not-reverted nil))
  1321.                      (dispatch-event ch))
  1322.                    (if (eq (event-to-character ch) ?\ )
  1323.                        (set-window-configuration conf)
  1324.                        (setq unread-command-event ch)))))))))
  1325.  
  1326. ; Ergo bindings
  1327. ; (global-set-key "\M-\t" 'comint-replace-by-expanded-filename)
  1328. ; (global-set-key "\M-?" 'comint-dynamic-list-completions)
  1329. ; (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete)
  1330.  
  1331. ;;; Converting process modes to use comint mode
  1332. ;;; ===========================================================================
  1333. ;;; Several gnu packages (tex-mode, background, dbx, gdb, kermit, prolog, 
  1334. ;;; telnet are some) use the shell package as clients. Most of them would
  1335. ;;; be better off using the comint package, but they predate it. 
  1336. ;;;
  1337. ;;; Altering these packages to use comint mode should greatly
  1338. ;;; improve their functionality, and is fairly easy.
  1339. ;;; 
  1340. ;;; Renaming variables
  1341. ;;; Most of the work is renaming variables and functions. These are the common
  1342. ;;; ones:
  1343. ;;; Local variables:
  1344. ;;;     last-input-end        comint-last-input-end
  1345. ;;;     last-input-start        comint-last-input-start
  1346. ;;;    shell-prompt-pattern    comint-prompt-regexp
  1347. ;;;     shell-set-directory-error-hook <no equivalent>
  1348. ;;; Miscellaneous:
  1349. ;;;    shell-set-directory    <unnecessary>
  1350. ;;;     shell-mode-map        comint-mode-map
  1351. ;;; Commands:
  1352. ;;;    shell-send-input    comint-send-input
  1353. ;;;    shell-send-eof        comint-delchar-or-maybe-eof
  1354. ;;;     kill-shell-input    comint-kill-input
  1355. ;;;    interrupt-shell-subjob    comint-interrupt-subjob
  1356. ;;;    stop-shell-subjob    comint-stop-subjob
  1357. ;;;    quit-shell-subjob    comint-quit-subjob
  1358. ;;;    kill-shell-subjob    comint-kill-subjob
  1359. ;;;    kill-output-from-shell    comint-kill-output
  1360. ;;;    show-output-from-shell    comint-show-output
  1361. ;;;    copy-last-shell-input    Use comint-previous-input/comint-next-input
  1362. ;;;
  1363. ;;; LAST-INPUT-START is no longer necessary because inputs are stored on the
  1364. ;;; input history ring. SHELL-SET-DIRECTORY is gone, its functionality taken
  1365. ;;; over by SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-sentinel.
  1366. ;;; Comint mode does not provide functionality equivalent to 
  1367. ;;; shell-set-directory-error-hook; it is gone.
  1368. ;;; 
  1369. ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
  1370. ;;; *not* create the comint-mode local variables in your foo-mode function.
  1371. ;;; This is not modular.  Instead, call comint-mode, and let *it* create the
  1372. ;;; necessary comint-specific local variables. Then create the
  1373. ;;; foo-mode-specific local variables in foo-mode.  Set the buffer's keymap to
  1374. ;;; be foo-mode-map, and its mode to be foo-mode.  Set the comint-mode hooks
  1375. ;;; (comint-prompt-regexp, comint-input-filter, comint-input-sentinel,
  1376. ;;; comint-get-old-input) that need to be different from the defaults.  Call
  1377. ;;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself;
  1378. ;;; comint-mode will take care of it. The following example, from cmushell.el,
  1379. ;;; is typical:
  1380. ;;; 
  1381. ;;; (defun shell-mode ()
  1382. ;;;   (interactive)
  1383. ;;;   (comint-mode)
  1384. ;;;   (setq comint-prompt-regexp shell-prompt-pattern)
  1385. ;;;   (setq major-mode 'shell-mode)
  1386. ;;;   (setq mode-name "Shell")
  1387. ;;;   (cond ((not shell-mode-map)
  1388. ;;;          (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map))
  1389. ;;;          (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete)
  1390. ;;;          (define-key shell-mode-map "\M-?"
  1391. ;;;                      'comint-dynamic-list-completions)))
  1392. ;;;   (use-local-map shell-mode-map)
  1393. ;;;   (make-local-variable 'shell-directory-stack)
  1394. ;;;   (setq shell-directory-stack nil)
  1395. ;;;   (setq comint-input-sentinel 'shell-directory-tracker)
  1396. ;;;   (run-hooks 'shell-mode-hook))
  1397. ;;;
  1398. ;;;
  1399. ;;; Note that make-comint is different from make-shell in that it
  1400. ;;; doesn't have a default program argument. If you give make-shell
  1401. ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name,
  1402. ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument
  1403. ;;; of NIL, it barfs. Adjust your code accordingly...
  1404. ;;;
  1405.  
  1406. ;;; Do the user's customisation...
  1407.  
  1408. (defvar comint-load-hook nil
  1409.   "This hook is run when comint is loaded in.
  1410. This is a good place to put keybindings.")
  1411.     
  1412. (run-hooks 'comint-load-hook)
  1413.  
  1414. ;;; Change log:
  1415. ;;; 9/12/89 
  1416. ;;;  - Souped up the filename expansion procedures.
  1417. ;;;    Doc strings are much clearer and more detailed.
  1418. ;;;    Fixed a bug where doing a filename completion when the point
  1419. ;;;    was in the middle of the filename instead of at the end would lose.
  1420. ;;;
  1421. ;;; 2/17/90 
  1422. ;;;  - Souped up the command history stuff so that text inserted
  1423. ;;;    by comint-previous-input-matching is removed by following
  1424. ;;;    command history recalls. comint-next/previous-input-matching
  1425. ;;;    is now much more smoothly integrated w/the command history stuff.
  1426. ;;;  - Added comint-eol-on-send flag and comint-input-sender hook.
  1427. ;;;    Comint-input-sender based on code contributed by Jeff Peck
  1428. ;;;    (peck@sun.com).
  1429. ;;;
  1430. ;;; 3/13/90 ccm@cmu.cs.edu
  1431. ;;;  - Added comint-previous-similar-input for looking up similar inputs.
  1432. ;;;  - Added comint-send-and-get-output to allow snarfing input from
  1433. ;;;    buffer. 
  1434. ;;;  - Added the ability to pick up a source file by positioning over
  1435. ;;;    a string in comint-get-source.
  1436. ;;;  - Added add-hook to make it a little easier for the user to use
  1437. ;;;    multiple hooks.
  1438. ;;;  
  1439. ;;; 5/22/90 shivers
  1440. ;;; - Moved Chris' multiplexed ipc stuff to comint-ipc.el.
  1441. ;;; - Altered Chris' comint-get-source string feature. The string
  1442. ;;;   is only offered as a default if it names an existing file.
  1443. ;;; - Changed comint-exec to directly crank up the process, instead
  1444. ;;;   of calling the env program. This made background.el happy.
  1445. ;;; - Added new buffer-local var comint-ptyp. The problem is that
  1446. ;;;   the signalling functions don't work as advertised. If you are
  1447. ;;;   communicating via pipes, the CURRENT-GROUP arg is supposed to
  1448. ;;;   be ignored, but, unfortunately it seems to be the case that you
  1449. ;;;   must pass a NIL for this arg in the pipe case. COMINT-PTYP
  1450. ;;;   is a flag that tells whether the process is communicating
  1451. ;;;   via pipes or a pty. The comint signalling functions use it
  1452. ;;;   to determine the necessary CURRENT-GROUP arg value. The bug
  1453. ;;;   has been reported to the Gnu folks.
  1454. ;;; - comint-dynamic-complete flushes the help window if you hit space
  1455. ;;;   after you execute it.
  1456. ;;; - Added functions comint-send-string, comint-send-region and var 
  1457. ;;;   comint-input-chunk-size.  comint-send-string tries to prevent processes
  1458. ;;;   from hanging when you send them long strings by breaking them into
  1459. ;;;   chunks and allowing process output between chunks. I got the idea from
  1460. ;;;   Eero Simoncelli's Common Lisp package. Note that using
  1461. ;;;   comint-send-string means that the process buffer's contents can change
  1462. ;;;   during a call!  If you depend on process output only happening between
  1463. ;;;   toplevel commands, this could be a problem. In such a case, use
  1464. ;;;   process-send-string instead. If this is a problem for people, I'd like
  1465. ;;;   to hear about it.
  1466. ;;; - Added comint-proc-query as a simple mechanism for commands that
  1467. ;;;   want to query an inferior process and display its response. For a
  1468. ;;;   typical use, see lisp-show-arglist in cmulisp.el.
  1469. ;;; - Added constant comint-version, which is now "2.01".
  1470. ;;;
  1471. ;;; 6/14/90 shivers
  1472. ;;; - Had comint-update-env defined twice. Removed extra copy. Also
  1473. ;;;   renamed mem to be comint-mem, for modularity. The duplication
  1474. ;;;   was reported by Michael Meissner.
  1475. ;;; 6/16/90 shivers
  1476. ;;; - Emacs has two different mechanisms for maintaining the process
  1477. ;;;   environment, determined at compile time by the MAINTAIN-ENVIRONMENT
  1478. ;;;   #define. One uses the process-environment global variable, and
  1479. ;;;   one uses a getenv/setenv interface. comint-exec assumed the
  1480. ;;;   process-environment interface; it has been generalised (with
  1481. ;;;   comint-exec-1) to handle both cases. Pretty bogus. We could,
  1482. ;;;   of course, skip all this and just use the etc/env program to
  1483. ;;;   handle the environment tweaking, but that obscures process
  1484. ;;;   queries that other modules (like background.el) depend on. etc/env
  1485. ;;;   is also fairly bogus. This bug, and some of the fix code was
  1486. ;;;   reported by Dan Pierson.
  1487. ;;;
  1488. ;;; 9/5/90 shivers
  1489. ;;; - Changed make-variable-buffer-local's to make-local-variable's.
  1490. ;;;   This leaves non-comint-mode buffers alone. Stephane Payrard
  1491. ;;;   reported the sloppy useage.
  1492. ;;; - You can now go from comint-previous-similar-input to
  1493. ;;;   comint-previous-input with no problem.
  1494. ;;;
  1495. ;;; 12/21/90 shivers
  1496. ;;; - Added a condition-case to comint-get-source. Bogus strings
  1497. ;;;   beginning with ~ were making the file-exists-p barf.
  1498. ;;; - Added "=" to the set of chars recognised by file completion
  1499. ;;;   as constituting a filename.
  1500. ;;;
  1501. ;;; 1/90 shivers
  1502. ;;; These changes comprise release 2.02:
  1503. ;;; - Removed the kill-all-local-variables in comint-mode. This
  1504. ;;;   made it impossible for client modes to set things before calling
  1505. ;;;   comint-mode. (In particular, it messed up ilisp.el) In general,
  1506. ;;;   the client mode should be responsible for a k-a-l-v's.
  1507. ;;; - Fixed comint-match-partial-pathname so that it works in
  1508. ;;;   more cases: if the filename begins at the start-of-buffer;
  1509. ;;;   if point is on the first char of the filename. Just a question
  1510. ;;;   of getting the tricky bits right.
  1511. ;;; - Added a hook, comint-exec-hook that is run each time a process
  1512. ;;;   is cranked up. Useful for things like process-kill-without-query.
  1513.